﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using YJKAprollDesign.BaseLineManage;
using YJKAprollDesign.DataDefine;
using YJKAprollDesign.FamilyCreate;
using YJKAprollDesign.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using YArchitech.Controls;
using YArchitech.Revit;
using YJKArchUtils.Utils;
using YJKArchUtils.Utils.Generics;
using YJKRevitBase.WinForm;
using YRevitJig;

namespace YJKAprollDesign
{
	public class AprollDesigner
	{
		public AprollDesigner(ExternalCommandData commandData)
		{
			this.m_Revit = commandData;
			this.m_Doc = this.m_Revit.Application.ActiveUIDocument.Document;
			this.m_ActiveView = this.m_Revit.Application.ActiveUIDocument.ActiveView;
			this.m_uiDoc = this.m_Revit.Application.ActiveUIDocument;
			this.m_drawJigCurve = new DrawJigCurve(commandData);
			this.m_controllerBaseLine = new BaseLineController(this.m_Revit);
		}

		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		public Result SearchBaseLine(ref string message)
		{
			try
			{
				if (!this.SearchBaseLineByWall())
				{
					return Autodesk.Revit.UI.Result.Failed;
				}
			}
			catch (Exception ex)
			{
				message = ex.Message;
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public Result EditBaseLine(ref string message)
		{
			EditingInterfaceForm editingInterfaceForm = new EditingInterfaceForm();
			editingInterfaceForm.Show(AprollDesigner._hWndRevit);
			int wMsg = 7;
			AprollDesigner.SendMessage(AprollDesigner._hWndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
			Result result = Autodesk.Revit.UI.Result.Cancelled;
			try
			{
				this.m_controllerBaseLine.ExtractionBaseLineByView();
				for (;;)
				{
					switch (editingInterfaceForm.CurrentOperateType)
					{
					case EditingInterfaceForm.OperateType.OT_DrawLine:
						result = this.DrawJigLineRefCurve(editingInterfaceForm.IsContinuous);
						break;
					case EditingInterfaceForm.OperateType.OT_DrawRect:
						result = this.DrawJigRectRefCurve(editingInterfaceForm.IsContinuous);
						break;
					case EditingInterfaceForm.OperateType.OT_DrawArc3Pt:
						result = this.DrawJigArc3PtRefCurve(editingInterfaceForm.IsContinuous);
						break;
					case EditingInterfaceForm.OperateType.OT_DrawArcCenter:
						result = this.DrawJigArcCenterRefCurve();
						break;
					case EditingInterfaceForm.OperateType.OT_SelectCurve:
						result = this.SelectRefCurve();
						break;
					case EditingInterfaceForm.OperateType.OT_SelectRef:
						result = this.SelectReferenceBaseLine(this.m_controllerBaseLine);
						break;
					case EditingInterfaceForm.OperateType.OT_Reverse:
						result = this.BaseLineReverse(this.m_controllerBaseLine);
						break;
					case EditingInterfaceForm.OperateType.OT_Delete:
						result = this.DeleteBaseLine(this.m_controllerBaseLine);
						break;
					}
					if (result == Autodesk.Revit.UI.Result.Cancelled)
					{
						if (!editingInterfaceForm.PickButton)
						{
							break;
						}
						editingInterfaceForm.PickButton = false;
					}
					else if (result == Autodesk.Revit.UI.Result.Failed)
					{
						break;
					}
				}
			}
			catch (Exception ex)
			{
				editingInterfaceForm.Close();
				message = ex.Message;
				return Autodesk.Revit.UI.Result.Failed;
			}
			if (editingInterfaceForm.Text != "")
			{
				editingInterfaceForm.m_bIsSendEsc = false;
			}
			editingInterfaceForm.Close();
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public Result CreateAproll(ref string message)
		{
			CreateAprollForm createAprollForm = new CreateAprollForm();
			Result result;
			try
			{
				while (createAprollForm.ShowDialog() == DialogResult.OK)
				{
					if (createAprollForm.ResultStyle == CreateAprollForm.FormResultStyle.FRS_Search)
					{
						if (this.SearchBaseLine(ref message) != null)
						{
							return Autodesk.Revit.UI.Result.Cancelled;
						}
					}
					else
					{
						if (createAprollForm.ResultStyle != CreateAprollForm.FormResultStyle.FRS_Edit)
						{
							return this.CreateAprollBySelection(createAprollForm);
						}
						if (this.EditBaseLine(ref message) != null)
						{
							return Autodesk.Revit.UI.Result.Cancelled;
						}
					}
				}
				this.DeleteBaseLineElements();
				result = Autodesk.Revit.UI.Result.Cancelled;
			}
			catch (Exception)
			{
				this.DeleteBaseLineElements();
				result = Autodesk.Revit.UI.Result.Failed;
			}
			return result;
		}

		private Result CreateAprollBySelection(CreateAprollForm dlg)
		{
			List<Element> list = new List<Element>();
			if (!this.SelectBaseLine(ref list))
			{
				return Autodesk.Revit.UI.Result.Cancelled;
			}
			if (list.Count < 1)
			{
				YJKMessageBox.Show("未选中任何散水边线");
				return Autodesk.Revit.UI.Result.Failed;
			}
			List<List<EdgeInfo>> list2 = new List<List<EdgeInfo>>();
			if (!this.GetAprollPathBySelection(list, true, ref list2))
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			List<List<EdgeInfo>> list3 = new List<List<EdgeInfo>>();
			for (int i = 0; i < list2.Count; i++)
			{
				List<EdgeInfo> item = list2[i];
				if (this.MergeCurveAndSetClockwise(ref item))
				{
					list3.Add(item);
				}
			}
			this.BreakLoopsInTheDoorPosition(ref list3);
			if (Geometry.GreaterThan(dlg.Offset, 0.0))
			{
				this.OffsetAprollPath(dlg.Offset, ref list3);
			}
			double aprollWidth = dlg.AprollWidth;
			double aprollMinHeight = dlg.AprollMinHeight;
			double aprollMaxHeight = aprollMinHeight + aprollWidth * dlg.AprollAngle / 100.0;
			ElementId materialId = null;
			AprollFamilyManager aprollFamilyManager = new AprollFamilyManager(this.m_Revit, materialId);
			string message = "";
			if (!aprollFamilyManager.CreateAproll(aprollMaxHeight, aprollMinHeight, aprollWidth, list3, dlg.LevelOffset, ref message))
			{
				YJKMessageBox.Show(message);
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public void DeleteBaseLineElements()
		{
			List<Element> list = new List<Element>();
			if (!this.SelectBaseLine(ref list))
			{
				return;
			}
			Transaction transaction = new Transaction(this.m_Doc);
			transaction.Start("delete baseline curves");
			foreach (Element element in list)
			{
				try
				{
					this.m_Doc.Delete(element.Id);
				}
				catch (Exception)
				{
				}
			}
			transaction.Commit();
		}

		private bool IsSelfIntersection(List<List<EdgeInfo>> aprollPathList)
		{
			foreach (List<EdgeInfo> list in aprollPathList)
			{
				for (int i = 0; i < list.Count; i++)
				{
					Curve curve = list[i].ConvertTo(this.m_Doc.Application);
					for (int j = i + 1; j < list.Count; j++)
					{
						Curve curve2 = list[j].ConvertTo(this.m_Doc.Application);
						IntersectionResultArray intersectionResultArray;
                        if ((int)curve.Intersect(curve2, out intersectionResultArray) == 8)
						{
							foreach (object obj in intersectionResultArray)
							{
								IntersectionResult intersectionResult = (IntersectionResult)obj;
								if (!intersectionResult.XYZPoint.IsAlmostEqualTo(list[i].StartPoint) && !intersectionResult.XYZPoint.IsAlmostEqualTo(list[i].EndPoint))
								{
									return true;
								}
								if (!intersectionResult.XYZPoint.IsAlmostEqualTo(list[j].StartPoint) && !intersectionResult.XYZPoint.IsAlmostEqualTo(list[j].EndPoint))
								{
									return true;
								}
							}
						}
					}
				}
			}
			return false;
		}

		private void OffsetAprollPath(double offset, ref List<List<EdgeInfo>> aprollPathList)
		{
			double val = Common.MMToFeet(0.8);
			for (int i = 0; i < aprollPathList.Count; i++)
			{
				DoubleLineCliper doubleLineCliper = new DoubleLineCliper(this.m_Revit.Application.Application);
				List<double> list = new List<double>();
				for (int j = 0; j < aprollPathList[i].Count; j++)
				{
					list.Add(offset);
				}
				List<ThreeLine> list2 = doubleLineCliper.CalculaterDoubleLine(aprollPathList[i], list, list);
				aprollPathList[i].Clear();
				foreach (ThreeLine threeLine in list2)
				{
					if (Geometry.GreaterThan(threeLine.RightLine.Length(), val))
					{
						aprollPathList[i].Add(threeLine.RightLine);
					}
				}
			}
		}

		private bool SelectBaseLine(ref List<Element> baselineList)
		{
			new BaseLineFilter(true);
			foreach (Element element in new FilteredElementCollector(this.m_Doc, this.m_Doc.ActiveView.Id).OfClass(typeof(CurveElement)).ToElements())
			{
				if (!(element.GetType() != typeof(DetailLine)) || !(element.GetType() != typeof(DetailArc)))
				{
					DetailCurve detailCurve = element as DetailCurve;
					if (detailCurve.LineStyle.Name.CompareTo("AprollBaseLine") == 0 || detailCurve.LineStyle.Name.CompareTo("TempLine") == 0)
					{
						baselineList.Add(detailCurve);
					}
				}
			}
			return baselineList.Count != 0;
		}

		private bool MergeCurveAndSetClockwise(ref List<EdgeInfo> mergedAprollPath)
		{
			new BaseLineController(this.m_Revit).MergeLinkedCurve(ref mergedAprollPath);
			List<XYZ> list = new List<XYZ>();
			foreach (EdgeInfo edgeInfo in mergedAprollPath)
			{
				Curve curve = null;
				try
				{
					curve = edgeInfo.ConvertTo(this.m_Revit.Application.Application);
				}
				catch (Exception)
				{
					continue;
				}
				if (!(curve == null))
				{
					IList<XYZ> list2 = curve.Tessellate();
					for (int i = 1; i < list2.Count; i++)
					{
						list.Add(list2[i]);
					}
				}
			}
			return true;
		}

		private bool SearchBaseLineByWall()
		{
			BaseLineController baseLineController = new BaseLineController(this.m_Revit);
			baseLineController.ExtractionBaseLineByView();
			if (!baseLineController.SearchBaseLineByWall())
			{
				return false;
			}
			baseLineController.RedrawBaseLine();
			return true;
		}

		private bool GetAprollPathBySelection(List<Element> baseLineList, bool deleteBaseLine, ref List<List<EdgeInfo>> aprollPathList)
		{
			BaseLineController baseLineController = new BaseLineController(this.m_Revit);
			if (!baseLineController.ExtractionBaseLineBySelection(baseLineList))
			{
				return false;
			}
			baseLineController.GetPathList(ref aprollPathList);
			if (this.IsSelfIntersection(aprollPathList))
			{
				YJKMessageBox.Show("连续的散水边线中存在自交，无法生成散水");
				return false;
			}
			if (deleteBaseLine)
			{
				baseLineController.DeleteBaseLineElements();
			}
			return true;
		}

		private string GetstatusPromptWithLine(int index)
		{
			string result = "选择直线边线的起始点";
			if (index % 2 == 1)
			{
				result = "选择直线边线的终点";
			}
			return result;
		}

		private string GetstatusPromptWithRect(int index)
		{
			string result = "选择散水定位线矩形的起始点";
			if (index % 2 == 1)
			{
				result = "选择散水定位线矩形的终点";
			}
			return result;
		}

		private bool IsContinuous(bool isContinuous)
		{
			return isContinuous && this.m_PickLastPoint != null;
		}

		private void DrawLines(List<Curve> lstCurves)
		{
			try
			{
				foreach (Curve curve in lstCurves)
				{
					XYZ hyendPoint = curve.GetEndPoint(0);
					XYZ hyendPoint2 = curve.GetEndPoint(1);
					if (curve is Line)
					{
						BaseLineSegment segment = new BaseLineSegment(new EdgeInfo(hyendPoint, hyendPoint2, 0.0));
						string message = "";
						if (!this.m_controllerBaseLine.AddBaseLineSegment(segment, ref message))
						{
							YJKMessageBox.Show(message);
							break;
						}
					}
					else
					{
						Arc arc = curve as Arc;
						bool isAnticlockwise = arc.Normal.IsAlmostEqualTo(XYZ.BasisZ);
						double bulge = Geometry.GetBulge(hyendPoint, hyendPoint2, arc.Center, isAnticlockwise);
						EdgeInfo edgeInfo = new EdgeInfo(hyendPoint, hyendPoint2, bulge);
						if (Geometry.LessThan(bulge, 0.0))
						{
							edgeInfo = new EdgeInfo(hyendPoint2, hyendPoint, -bulge);
						}
						BaseLineSegment segment2 = new BaseLineSegment(edgeInfo);
						string message2 = "";
						if (!this.m_controllerBaseLine.AddBaseLineSegment(segment2, ref message2))
						{
							YJKMessageBox.Show(message2);
							break;
						}
					}
					this.m_controllerBaseLine.RedrawBaseLine();
				}
			}
			catch
			{
			}
		}

		private Result DrawJigLineRefCurve(bool bIsContinuous)
		{
			try
			{
				for (;;)
				{
					List<Curve> lstCurves = new List<Curve>();
					if (!bIsContinuous)
					{
						this.m_PickLastPoint = null;
					}
					if (this.m_drawJigCurve.DrawJigCurveLine(ref lstCurves, ref this.m_PickLastPoint, this.GetstatusPromptWithLine(0), this.GetstatusPromptWithLine(1)) != null)
					{
						break;
					}
					if (!bIsContinuous)
					{
						this.m_PickLastPoint = null;
					}
					this.DrawLines(lstCurves);
				}
			}
			catch (Exception)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Cancelled;
		}

		private Result DrawJigRectRefCurve(bool bIsContinuous)
		{
			try
			{
				for (;;)
				{
					List<Curve> lstCurves = new List<Curve>();
					if (!bIsContinuous)
					{
						this.m_PickLastPoint = null;
					}
					if (this.m_drawJigCurve.DrawJigCurveRect(ref lstCurves, this.GetstatusPromptWithRect(0), this.GetstatusPromptWithRect(1)) != null)
					{
						break;
					}
					if (!bIsContinuous)
					{
						this.m_PickLastPoint = null;
					}
					this.DrawLines(lstCurves);
				}
			}
			catch (Exception)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Cancelled;
		}

		private Result DrawJigArc3PtRefCurve(bool bIsContinuous)
		{
			try
			{
				for (;;)
				{
					List<Curve> lstCurves = new List<Curve>();
					if (!bIsContinuous)
					{
						this.m_PickLastPoint = null;
					}
					if (this.m_drawJigCurve.DrawJigCurveArc3Pt(ref lstCurves, ref this.m_PickLastPoint, this.GetstatusPromptWithArc3Pt(0), this.GetstatusPromptWithArc3Pt(1), this.GetstatusPromptWithArc3Pt(2)) != null)
					{
						break;
					}
					if (!bIsContinuous)
					{
						this.m_PickLastPoint = null;
					}
					this.DrawLines(lstCurves);
				}
			}
			catch (Exception)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Cancelled;
		}

		private Result DrawJigArcCenterRefCurve()
		{
			this.m_PickLastPoint = null;
			try
			{
				for (;;)
				{
					List<Curve> lstCurves = new List<Curve>();
					if (this.m_drawJigCurve.DrawJigCurveArcCenter2Pt(ref lstCurves, this.GetstatusPromptWithArcCenter(0), this.GetstatusPromptWithArcCenter(1), this.GetstatusPromptWithArcCenter(2)) != null)
					{
						break;
					}
					this.DrawLines(lstCurves);
				}
			}
			catch (Exception)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Cancelled;
		}

		private string GetstatusPromptWithArc3Pt(int index)
		{
			string result = "选择弧形边线的起始点";
			if (index % 3 == 1)
			{
				result = "选择弧形边线的终点";
			}
			else if (index % 3 == 2)
			{
				result = "选择弧形边线的线上点";
			}
			return result;
		}

		private string GetstatusPromptWithArcCenter(int index)
		{
			string result = "选择弧形边线的圆心";
			if (index % 3 == 1)
			{
				result = "选择弧形边线的起始点";
			}
			else if (index % 3 == 2)
			{
				result = "选择弧形边线的终点";
			}
			return result;
		}

		private Result SelectReferenceBaseLine(BaseLineController controller)
		{
			this.m_PickLastPoint = null;
			try
			{
				Curve curve = null;
				while (this.PickEdge(ref curve))
				{
					BaseLineSegment segment = new BaseLineSegment(new EdgeInfo(curve, false));
					string message = "";
					if (!controller.AddBaseLineSegment(segment, ref message))
					{
						YJKMessageBox.Show(message);
					}
					controller.RedrawBaseLine();
				}
			}
			catch (Exception)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Cancelled;
		}

		private Result SelectRefCurve()
		{
			Result result = 0;
			for (;;)
			{
				try
				{
					List<Curve> list = new List<Curve>();
					CurveFilter curveFilter = new CurveFilter();
					Reference reference = this.m_Revit.Application.ActiveUIDocument.Selection.PickObject((Autodesk.Revit.UI.Selection.ObjectType)1, curveFilter, "拾取详图线生成定位线");
					Curve curve = ((this.m_Doc.GetElement(reference) as DetailCurve).Location as LocationCurve).Curve;
					list.Add(curve);
					this.DrawLines(list);
					continue;
				}
				catch (Exception)
				{
					result = Autodesk.Revit.UI.Result.Cancelled;
				}
				break;
			}
			return result;
		}

		private Result BaseLineReverse(BaseLineController controller)
		{
			this.m_PickLastPoint = null;
			try
			{
				Curve curve = null;
				while (this.PickBaseLine(ref curve))
				{
					BaseLineSegment segment = null;
					if (controller.FindBaseLineSegment(new EdgeInfo(curve, false), ref segment))
					{
						controller.ChangeBaseLineSegmentOrientation(segment);
						controller.RedrawBaseLine();
					}
				}
			}
			catch (Exception)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Cancelled;
		}

		private Result DeleteBaseLine(BaseLineController controller)
		{
			this.m_PickLastPoint = null;
			try
			{
				List<Element> list = new List<Element>();
				while (this.PickBaseLine(ref list))
				{
					if (list.Count != 0)
					{
						Transaction transaction = new Transaction(this.m_Doc);
						transaction.Start("delete baseLine");
						foreach (Element element in list)
						{
							try
							{
								this.m_Doc.Delete(element.Id);
							}
							catch (Exception)
							{
							}
						}
						transaction.Commit();
						controller.ExtractionBaseLineByView();
						controller.RedrawBaseLine();
					}
				}
			}
			catch (Exception)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Cancelled;
		}

		private bool PickEdge(ref Curve refCurve)
		{
			Reference reference = null;
			Selection selection = this.m_Revit.Application.ActiveUIDocument.Selection;
			try
			{
				WallFaceFilter wallFaceFilter = new WallFaceFilter(this.m_Doc);
				reference = selection.PickObject((Autodesk.Revit.UI.Selection.ObjectType)4, wallFaceFilter, "选择墙边界生成边线");
			}
			catch (Exception)
			{
				return false;
			}
			if (reference == null)
			{
				return false;
			}
			Face face = this.m_Doc.GetElement(reference).GetGeometryObjectFromReference(reference) as Face;
			if (null == face)
			{
				return false;
			}
			XYZ globalPoint = reference.GlobalPoint;
			double val = double.MaxValue;
			Curve curve = null;
			foreach (object obj in face.EdgeLoops)
			{
				foreach (object obj2 in ((EdgeArray)obj))
				{
					Curve curve2 = ((Edge)obj2).AsCurve();
					XYZ endPoint = curve2.GetEndPoint(0);
					XYZ endPoint2 = curve2.GetEndPoint(1);
					if (Geometry.IsEqual(endPoint.Z, endPoint2.Z))
					{
						double num = curve2.Distance(new XYZ(globalPoint.X, globalPoint.Y, endPoint.Z));
						if (Geometry.LessThan(num, val))
						{
							val = num;
							curve = curve2;
						}
					}
				}
			}
			if (curve == null)
			{
				return false;
			}
			refCurve = curve;
			return true;
		}

		private bool PickBaseLine(ref Curve baseLineCurve)
		{
			Selection selection = this.m_Revit.Application.ActiveUIDocument.Selection;
			try
			{
				BaseLineFilter baseLineFilter = new BaseLineFilter(false);
				Reference reference = selection.PickObject((Autodesk.Revit.UI.Selection.ObjectType)1, baseLineFilter, "选择边线");
				DetailCurve detailCurve = this.m_Doc.GetElement(reference) as DetailCurve;
				baseLineCurve = detailCurve.GeometryCurve;
			}
			catch (Exception)
			{
				return false;
			}
			return true;
		}

		private bool PickBaseLine(ref List<Element> baseLineList)
		{
			Selection selection = this.m_Revit.Application.ActiveUIDocument.Selection;
			RevitVersionFuncs.ClearSelection(selection);
			try
			{
				BaseLineFilter baseLineFilter = new BaseLineFilter(false);
				foreach (Element element in selection.PickElementsByRectangle(baseLineFilter, "选择边线"))
				{
					DetailCurve item = element as DetailCurve;
					baseLineList.Add(item);
				}
			}
			catch (Exception)
			{
				return false;
			}
			return true;
		}

		private XYZ Get2DXYZ(XYZ point3d)
		{
			return new XYZ(point3d.X, point3d.Y, 0.0);
		}

		private void BreakLoopsInTheDoorPosition(ref List<List<EdgeInfo>> aprollPathList)
		{
			List<DoorInfo> list = new List<DoorInfo>();
			ElementCategoryFilter elementCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors);
			foreach (Element element in new FilteredElementCollector(this.m_Doc, this.m_ActiveView.Id).OfClass(typeof(FamilyInstance)).WherePasses(elementCategoryFilter).ToElements())
			{
				FamilyInstance familyInstance = element as FamilyInstance;
				if (familyInstance.Location != null)
				{
					XYZ position = this.Get2DXYZ((familyInstance.Location as LocationPoint).Point);
					XYZ facingOrientation = familyInstance.FacingOrientation;
					Parameter parameter = familyInstance.Symbol.get_Parameter(BuiltInParameter.CASEWORK_WIDTH);
					if (parameter != null)
					{
						double width = parameter.AsDouble();
						double width2 = (familyInstance.Host as Wall).Width;
						DoorInfo item = new DoorInfo(position, facingOrientation, width, width2);
						list.Add(item);
					}
				}
			}
			List<EdgeInfo> list2 = new List<EdgeInfo>();
			for (int i = 0; i < aprollPathList.Count; i++)
			{
				for (int j = 0; j < aprollPathList[i].Count; j++)
				{
					this.BreakSingleEdge(aprollPathList[i][j], ref list, ref list2);
				}
			}
			aprollPathList.Clear();
			BaseLineController baseLineController = new BaseLineController(this.m_Revit);
			string text = "";
			foreach (EdgeInfo edgeInfo in list2)
			{
				baseLineController.AddBaseLineSegment(new BaseLineSegment(edgeInfo), ref text);
			}
			baseLineController.GetPathList(ref aprollPathList);
		}

		private void BreakSingleEdge(EdgeInfo edgeInfo, ref List<DoorInfo> doorInfoList, ref List<EdgeInfo> breakedEdges)
		{
			List<XYZ> list = new List<XYZ>();
			for (int i = 0; i < doorInfoList.Count; i++)
			{
				if (doorInfoList[i].IsLinked(edgeInfo))
				{
					XYZ item = null;
					XYZ item2 = null;
					doorInfoList[i].GetEndsOnEdgeInfo(edgeInfo, ref item, ref item2);
					list.Add(item);
					list.Add(item2);
					doorInfoList.RemoveAt(i);
					i--;
				}
			}
			if (list.Count == 0)
			{
				breakedEdges.Add(edgeInfo);
				return;
			}
			XYZ center = edgeInfo.Center;
			bool flag = true;
			if (!edgeInfo.Normal.IsAlmostEqualTo(XYZ.BasisZ))
			{
				flag = false;
			}
			if (edgeInfo.IsArc)
			{
				if (flag)
				{
					list.Sort(new YJKArchUtils.Utils.Generics.AngleComparer(edgeInfo.StartPoint, center));
				}
				else
				{
					list.Sort(new YJKArchUtils.Utils.Generics.AngleComparer(edgeInfo.EndPoint, center));
					list.Reverse();
				}
			}
			else
			{
				list.Sort(new DistanceComparer(edgeInfo.StartPoint));
			}
			list.Insert(0, edgeInfo.StartPoint);
			list.Add(edgeInfo.EndPoint);
			for (int i = 0; i < list.Count; i += 2)
			{
				XYZ xyz = list[i];
				XYZ xyz2 = list[i + 1];
				double bulge = 0.0;
				if (edgeInfo.IsArc)
				{
					bulge = Geometry.GetBulge(xyz, xyz2, center, flag);
				}
				EdgeInfo item3 = new EdgeInfo(xyz, xyz2, bulge);
				breakedEdges.Add(item3);
			}
		}

        public static WindowHandle _hWndRevit;

		private ExternalCommandData m_Revit;

		private Document m_Doc;

		private Autodesk.Revit.DB.View m_ActiveView;

		private XYZ m_PickLastPoint;

		private UIDocument m_uiDoc;

		private BaseLineController m_controllerBaseLine;

		private DrawJigCurve m_drawJigCurve;
	}
}
